home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / misc / TownMaze.lha / TownMaze / src.lzh / nhbrexists.c < prev    next >
C/C++ Source or Header  |  1991-08-04  |  1KB  |  51 lines

  1. /*
  2. ** nhbrexists.c  Copyright 1991 Kent Paul Dolan,
  3. **               Mountain View, CA, USA 94039-0755
  4. **
  5. ** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  6. ** May be freely used or modified in any non-commercial work.  Copyrighted
  7. ** only to prevent patenting by someone else.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include "townmaze.h"
  12. #include "townproto.h"
  13.  
  14. #ifdef __STDC__
  15. int nhbrexists(int cellid,int nhbrid)
  16. #else
  17. int nhbrexists(cellid,nhbrid)
  18.   int cellid, nhbrid;
  19. #endif
  20. {
  21.   int celli, cellj;
  22.  
  23.   celli = cellid / (mazewidth/2);
  24.   cellj = cellid % (mazewidth/2);
  25.  
  26.   switch (nhbrid)
  27.   {
  28.     case 0: /* too far north? */
  29.       return (((celli - 1) < 0) ? (1==0) : (1==1));
  30.       break;
  31.  
  32.     case 1: /* too far east? */
  33.       return (((cellj + 1) >= (mazewidth/2)) ? (1==0) : (1==1));
  34.       break;
  35.  
  36.     case 2: /* too far south? */
  37.       return (((celli + 1) >= (mazeheight/2)) ? (1==0) : (1==1));
  38.       break;
  39.  
  40.     case 3:/* too far west? */
  41.       return (((cellj - 1) < 0) ? (1==0) : (1==1));
  42.       break;
  43.  
  44.     default:
  45.       fprintf(stderr,"bad neighbor id value to nhbrexists %d\n",nhbrid);
  46.       showdebugmaze();
  47.       freespace();
  48.       exit(1);
  49.   }
  50. }
  51.